public PrintParentheses {
  public void printPair(int n) {
      StringBuffer out = new StringBuffer();
      doPrint(0,0, n, out);

    }

  public void doPrint(int leftNum, int rightNum, int n, StringBuffer out) {
      
    //Constraint: LeftNum must exceed right number
      if(leftNum < rightNum) return;
      if(out.length() == 2 * n)
        System.out.println(out.toString());
        
      if(leftNum <= n) {  
        out.append("(");
        doPrint(leftNum+1, rightNum, n, out);
      }
      if(rightNum <= n) {
        out.append(")");
        doPrint(leftNum, rightNum+1, n, out);
      }
  }

}